

package cn.shengchao.controler;

import cn.shengchao.util.helper.LoginHelper;
import cn.shengchao.examstar.account.acl.ports.repositories.IBankCardRepository;
import cn.shengchao.examstar.account.domain.BankCard;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.web.model.R;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/backCard")
public class BackCardController {

    @Autowired
    private IBankCardRepository backCardRepository;

    //新增银行卡
    @PostMapping()
    public R save(@RequestBody BankCard bankCard) {
        long userId = LoginHelper.getUserId();
        backCardRepository.save(bankCard, userId);
        return R.ok();
    }

    //删除银行卡
    @DeleteMapping("{id}")
    public R delete(@PathVariable Long id) {
        backCardRepository.delete(id);
        return R.ok();
    }

    //查询银行卡
    @GetMapping
    public R<List<BankCard>> find() {
        long userId = LoginHelper.getUserId();
        return R.ok(backCardRepository.findByUserId(userId));
    }
}
